import { modal } from 'vue-strap'

import { showMsg, keyEventsList} from '../../../vuex/action'
import Tab from '../tab/tab.vue'
import Pages from '../../../component/pages/pages.vue'
import config from '../verify-config/config.vue'
import moment from 'moment'

export default {
  name: 'entry',
  components: {
    'vue-modal': modal,
    'vue-tab': Tab,
    'vue-pages': Pages,
    'vue-config': config
  },
  vuex: {
    getters: {
      fresh: state => state.inviteListFresh,
    },
    actions: {
      xShowMsg: showMsg,
      xGetList: keyEventsList
    }
  },
  data() {
    return {
      list: [],
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      }
    }
  },
  ready() {
    this.getList({})
  },
  methods: {
    addItem(it) {
      let ref = this.$refs.riskConfig
      ref.actionType = 'UPDATE'
      ref.form = it

      ref.form.startDt = moment(it.startDt).format('YYYY-MM-DD HH:mm:ss')
      ref.form.endDt = moment(it.endDt).format('YYYY-MM-DD HH:mm:ss')
      ref.getKpiList(it.eventId)
      ref.showModal = true
    },
    getList({ start = this.pages.start, limit = this.pages.limit }) {
      this.xGetList({
        type: '1',
        start: start,
        limit: limit
      })
        .then(data => {
          this.list = data.list
          this.pages.totalPages = Math.ceil(data.totalCount / limit)
        })
        .catch(res => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
  },
  watch: {
    fresh() {
      if (this.fresh) {
        this.getList({})
      }
    }
  }
}
